package common

import (
	"clientDemo/service/widget_data"
	widgetcommon "clientDemo/ui/fyne_ui/widget/interface"
)

var _ widgetcommon.ISkinInfo = (*SkinInfo)(nil)

type SkinInfo struct {
	BaseWidgetName string
	SkinName       string //模板名
	Attributes     []*widget_data.Property
	//Properties     map[string]string
	AllProperties []*widget_data.Property
	Children      []*SkinInfo
}

func NewSkinInfo(baseWidgetName, SkinName string) *SkinInfo {
	return &SkinInfo{
		BaseWidgetName: baseWidgetName,
		SkinName:       SkinName,
		//Properties:     make(map[string]string),
		//Attributes: make(map[string]string),
	}
}
func (w *SkinInfo) AddProperty(key, value string) {
	w.AllProperties = append(w.AllProperties, &widget_data.Property{Key: key, Value: value})
}
func (w *SkinInfo) GetAllProperty() []*widget_data.Property {
	return w.AllProperties
}

//	func (w *SkinInfo) SetProperty(key, value string) {
//		w.Properties[key] = value
//	}
//
//	func (w *SkinInfo) GetProperty() map[string]string {
//		return w.Properties
//	}
func (w *SkinInfo) GetSkinName() string {
	return w.SkinName
}
func (w *SkinInfo) GetBaseWidgetName() string {
	return w.BaseWidgetName
}

func (w *SkinInfo) SetAttribute(key, value string) {
	w.Attributes = append(w.Attributes, &widget_data.Property{Key: key, Value: value})
	//w.Attributes[key] = value
	//w.Properties[key] = value
}
func (w *SkinInfo) GetAttribute() []*widget_data.Property {
	return w.Attributes
}
func (w *SkinInfo) ForEachChild(f func(skinInfo widgetcommon.ISkinInfo)) {
	for _, child := range w.Children {
		f(child)
	}
}
